package com.zjdiepu.www.commpent.mapper.yw;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.stereotype.Component;

import com.zjdiepu.www.base.core.BaseMapper;
import com.zjdiepu.www.base.enums.status.AddedStatus1;
import com.zjdiepu.www.base.enums.status.ApplyDiviStatus;
import com.zjdiepu.www.base.enums.status.BusiStatus;
import com.zjdiepu.www.base.enums.status.CarinfoEditStatus;
import com.zjdiepu.www.base.enums.status.InterviewStatus;
import com.zjdiepu.www.base.enums.status.OpenCardStatus;
import com.zjdiepu.www.base.enums.status.PickCarStatus;
import com.zjdiepu.www.base.enums.status.ThirdBusiStatus;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.SysParamsType;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.commpent.RedisObjectClient;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.system.IBaseSysParamsService;
import com.zjdiepu.www.model.base.dto.SimpleDataDictionary;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.util.CachedEnums;
/**
 * 项目名称：dpqc-parent-manager-information <br/> 
 * 类名称：YwBusinessMapper <br/>  
 * 类描述：字段转换 <br/>    
 * 创建人：xiongxiaotun <br/> 
 * 创建时间：2017年4月25日 下午5:51:41  <br/>   
 * 修改人：xiongxiaotun <br/> 
 * 修改时间：2017年4月25日 下午5:51:41   <br/>  
 * 修改备注：    <br/> 
 * @version V1.0   <br/>
 */
@Component
public class YwBusinessVoMapper extends BaseMapper<YwBusiness>{
	@Resource
	private ICachedDictionaryService cachedDictionaryService;
	@Autowired
	private IBaseSysParamsService baseSysParamsService;
	@Autowired
	private RedisObjectClient redisObjectClient;

	@Override
	public void mapper(RedisConnection redisConnection,YwBusiness m) {
		if(null == m) {
			return;
		}
		Date loanTime = m.getLoanTime();
		if(loanTime == null) {
			m.setLoanTimeDisplay("-");
		} else {
			String dateTo8String = DateUtil.dateTo8String(loanTime);
			//垫款申请距审核完成的时间
			Integer overdueFundRetrial = (Integer)SysParamsType.DIAN_ZI_CHAO_QI_CHONG_SHEN.getDefaultValue();;
			String overdueFundRetrialValue = baseSysParamsService.getValueByCodeWithPool(redisConnection, SysParamsType.DIAN_ZI_CHAO_QI_CHONG_SHEN.getCode());
			if(StringUtils.isNotBlank(overdueFundRetrialValue)) {
				overdueFundRetrial = Integer.parseInt(overdueFundRetrialValue);
			}
			if(DateUtil.countDiffDateDays(loanTime, new Date()) > overdueFundRetrial) {
				m.setLoanTimeDisplay("<span style='color:red;'>" + dateTo8String + "</span>");
			} else {
				m.setLoanTimeDisplay(dateTo8String);
			}
		}
		Integer busiStatus = m.getBusiStatus();
		m.setBusiStatusDisplay((String)CachedEnums.getValue(busiStatus, BusiStatus.class));
		
		Integer openCardStatus = m.getOpenCardStatus();
		m.setOpenCardStatusDisplay((String)CachedEnums.getValue(openCardStatus, OpenCardStatus.class));
		
		Integer applyDiviStatus = m.getApplyDiviStatus();
		m.setApplyDiviStatusDisplay((String)CachedEnums.getValue(applyDiviStatus, ApplyDiviStatus.class));
		
		Integer addedStatus1 = m.getAddedStatus1();
		m.setAddedStatus1Display((String)CachedEnums.getValue(addedStatus1, AddedStatus1.class));
		
		Integer channelStatus = m.getChannelStatus();
		SimpleDataDictionary simpleDataDictionary1 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelStatus != null ? channelStatus.toString() : null, DataDicType.CHANNEL_STATUS.getCode());
		m.setChannelStatusDisplay(simpleDataDictionary1 == null ? "" : simpleDataDictionary1.getName());
		
		String channelType = m.getChannelType();
		SimpleDataDictionary simpleDataDictionary2 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), channelType, DataDicType.CHANNEL_TYPE.getCode());
		m.setChannelTypeDisplay(simpleDataDictionary2 == null ? "" : simpleDataDictionary2.getName());
		
		String dealerLevel = m.getDealerLevel();
		SimpleDataDictionary simpleDataDictionary3 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), dealerLevel, DataDicType.DEALER_LEVEL.getCode());
		m.setDealerLevelDisplay(simpleDataDictionary3 == null ? "" : simpleDataDictionary3.getName());
		
		String bankLoan = m.getBankLoan();
		SimpleDataDictionary simpleDataDictionary4 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), bankLoan, DataDicType.LOAN_BANK.getCode());
		m.setBankLoanDisplay(simpleDataDictionary4 == null ? "" : simpleDataDictionary4.getName());
		
		String carType = m.getCarType();
		SimpleDataDictionary simpleDataDictionary5 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), carType, DataDicType.CAR_TYPE.getCode());
		m.setCarTypeDisplay(simpleDataDictionary5 == null ? "" : simpleDataDictionary5.getName());
		
		String fundChannel = m.getFundChannel();
		SimpleDataDictionary simpleDataDictionary6 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), fundChannel, DataDicType.FUND_CHANNEL.getCode());
		m.setFundChannelDisplay(simpleDataDictionary6 == null ? "" : simpleDataDictionary6.getName());
		
		String busiType = m.getBusiType();
		SimpleDataDictionary simpleDataDictionary7 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), busiType, DataDicType.BUSI_TYPE.getCode());
		m.setBusiTypeDisplay(simpleDataDictionary7 == null ? "" : simpleDataDictionary7.getName());
		
		String fundToAccountStatus= m.getFundToAccountStatus();
		SimpleDataDictionary simpleDataDictionary8 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), fundToAccountStatus, DataDicType.FUNDTOACCOUNT_STATUS.getCode());
		m.setFundToAccountStatusDisplay(simpleDataDictionary8 == null ? "" : simpleDataDictionary8.getName());
		
		Integer thirdBusiStatus = m.getThirdBusiStatus();
		m.setThirdBusiStatusDisplay((String)CachedEnums.getValue(thirdBusiStatus, ThirdBusiStatus.class));
		
		Integer pickCarStatus = m.getPickCarStatus();
		m.setPickCarStatusDisplay((String)CachedEnums.getValue(pickCarStatus, PickCarStatus.class));
		
		String carinfoEditStatus = m.getCarinfoEditStatus();
		m.setCarinfoEditStatusDisplay((String)CachedEnums.getValue(carinfoEditStatus, CarinfoEditStatus.class));
		
		String hisCarManType = m.getHisCarManType();
		SimpleDataDictionary simpleDataDictionary9 = redisObjectClient.hGet(redisConnection, SimpleDataDictionary.class.getSimpleName(), hisCarManType, DataDicType.CREDIT_PEOPLE_TYPE.getCode());
		m.setHisCarManTypeDisplay(simpleDataDictionary9 == null ? "" : simpleDataDictionary9.getName());
		
		
		Integer interviewStatus = m.getInterviewStatus();
		m.setInterviewStatusDisplay((String)CachedEnums.getValue(interviewStatus, InterviewStatus.class));
	}
}
